package com.mck.service.impl;

import com.mck.entity.OperLog;
import com.mck.mapper.OperationLogMapper;
import com.mck.service.OperationLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.List;

@Service
@Slf4j
public class OperationLogServiceImpl implements OperationLogService {

    @Autowired
    private OperationLogMapper operationLogMapper;

    // 保存操作日志
    @Override
    @Transactional
    public void saveOperationLog(OperLog operationLog) {
        try {
            operationLog.setCreateTime(LocalDateTime.now());

            operationLogMapper.insertOperationLog(operationLog);
        } catch (Exception e) {
            log.error("保存操作日志失败", e);
        }
    }

    // 获取用户操作日志
    @Override
    public List<OperLog> getUserOperationLogs(Integer userId) {
        return operationLogMapper.getOperationLogList(userId);
    }
}